package com.ewo.controller.ApplicationPageController;

import com.ewo.entity.ApplicationPage.Notice;
import com.ewo.entity.ResponseResult;
import com.ewo.service.ApplicationPage.NoticeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/notice")
@CrossOrigin("*")
public class NoticeController {

    @Resource
    NoticeService noticeService;

    //查找所有公告信息
    @GetMapping("/allNotice")
    public ResponseResult findAllNotice() {
        List<Notice> noticeList = noticeService.findAllNotice();
        if (noticeList == null || noticeList.size() == 0) {
            return ResponseResult.fail();
        }
        return ResponseResult.ok(noticeList);
    }

    //更新公告已阅读信息
    @GetMapping("/reader/{id}")
    public ResponseResult updateNoticeById(@PathVariable("id") long id){
        //根据id更新阅读信息
        int rows = noticeService.updateNoticeById(id);
        //根据id获取当前正文text
        Notice notice = noticeService.findNoticeById(id);
        return rows==0?ResponseResult.fail():ResponseResult.ok(notice);
    }


}
